package com.rock.code.bigdata.synthesizequery.controller;

import com.rock.code.bigdata.synthesizequery.service.SyntheSizeQueryService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import java.text.SimpleDateFormat;
import java.util.*;

/**
 * @author piandu
 * @description 综合查询调用方法
 * @date 2018/9/14 16/34
 */
@Controller
@RequestMapping("/queryTime")
public class SynthSizeQueryController {
    /**
     * 折线图
     */
    @Resource
    private SyntheSizeQueryService syntheSizeQueryService;

    //按对象查询调用方法
    @ResponseBody
    @RequestMapping(value = "/Time", method = RequestMethod.POST)
    public List queryTime(String EXT_UNIT_ID, String KPI_CODE, String START, String END, String SELECT) {
        HashMap map = new HashMap();
        List list = new ArrayList();
        if (EXT_UNIT_ID != null && KPI_CODE != null) {
            map.put("EXT_UNIT_ID", EXT_UNIT_ID);
            map.put("KPI_CODE", KPI_CODE);
        }
        if ("showDay".equals(SELECT)) {
            map.put("START", START);
            map.put("END", END);
            String str1[] = START.split("-");
            String name = str1[0] + str1[1];
            String tableName = "tb_kpi_value_month_" + name;
            String str2[] = START.split("-");
            String name1 = str2[0] + str2[1];
            int b = 1;
            int a = Integer.parseInt(name1);
            int c = a + b;
            String tableName1 = "tb_kpi_value_month_" + c;
            String str3[] = END.split("-");
            String name2 = str3[0] + str3[1];
            String tableName2 = "tb_kpi_value_month_" + name2;
            map.put("table_one", tableName);
            map.put("table_three", tableName1);
            map.put("table_two", tableName2);
            map.put("start_time", START);
            map.put("end_time", END);
            list = syntheSizeQueryService.queryLineByDate1(map);

        } else if ("showMonth".equals(SELECT)) {
            map.put("START", START);
            map.put("END", END);
            String str1[] = START.split("-");
            String name = str1[0];
            String tableName = "tb_kpi_value_year_" + name;
            String str3[] = START.split("-");
            String name2 = str3[0];
            int b = 1;
            int a = Integer.parseInt(name2);
            int c = a + b;
            String tableName2 = "tb_kpi_value_year_" + c;
            String str2[] = END.split("-");
            String name1 = str2[0];
            String tableName1 = "tb_kpi_value_year_" + name1;
            map.put("table_one", tableName);
            map.put("table_three", tableName2);
            map.put("table_two", tableName1);
            map.put("start_time", START);
            map.put("end_time", END);
            list = syntheSizeQueryService.queryMonth(map);
        } else {
            //2018-08-01         tb_kpi_value_day_20170101
            String str[] = START.split("-");
            String name = str[0] + str[1] + str[2];
            String tableName = "tb_kpi_value_day_" + name;
            map.put("tableName", tableName);
            list = syntheSizeQueryService.queryTime(map);
        }
//        for (Object o : list) {
//            System.out.println(o);
//        }
        return list;
    }

    /**
     * 横_柱状图
     */
    @ResponseBody
    @RequestMapping(value = "/queryNum", method = RequestMethod.POST)
    public List queryNum(String EXT_UNIT_ID, String KPI_CODE, String START, String END) {
        HashMap map = new HashMap();
        if (EXT_UNIT_ID != null && KPI_CODE != null) {
            map.put("EXT_UNIT_ID", EXT_UNIT_ID);
            map.put("KPI_CODE", KPI_CODE);
        }
//        String tableName = "tb_kpi_value_month_201805";
        String str1[] = START.split("-");
        String name = str1[0] + str1[1];
        String tableName = "tb_kpi_value_month_" + name;
        String str3[] = END.split("-");
        String name2 = str3[0] + str3[1];
        String tableName2 = "tb_kpi_value_month_" + name2;
        if (tableName != null && START != null && END != null) {
//            map.put("tableName", tableName);
            map.put("tableName", "tb_kpi_value_month_201801");
//            map.put("start_time", START);
            map.put("start_time", "2018-01-01");
//            map.put("end_time", END);
            map.put("end_time", "2018-01-01");
        }
        List list = syntheSizeQueryService.queryState(map);
        return list;
    }

    //==============================================================================================================
    //按指标查询调用方法
    @ResponseBody
    @RequestMapping(value = "/targetQuery", method = RequestMethod.POST)
    public List queryTime1(String EXT_UNIT_ID, String KPI_ID, String START, String END, String SELECT) {
        HashMap map = new HashMap();
        List list = new ArrayList();
        if (EXT_UNIT_ID != null && KPI_ID != null) {
            map.put("EXT_UNIT_ID", EXT_UNIT_ID);
            map.put("KPI_ID", KPI_ID);
        }
        if ("showDay".equals(SELECT)) {
            map.put("START", START);
            map.put("END", END);
            String str1[] = START.split("-");
            String name = str1[0] + str1[1];
            String tableName = "tb_kpi_value_month_" + name;
            String str2[] = START.split("-");
            String name1 = str2[0] + str2[1];
            int b = 1;
            int a = Integer.parseInt(name1);
            int c = a + b;
            String tableName1 = "tb_kpi_value_month_" + c;
            String str3[] = END.split("-");
            String name2 = str3[0] + str3[1];
            String tableName2 = "tb_kpi_value_month_" + name2;
            map.put("table_one", tableName);
            map.put("table_three", tableName1);
            map.put("table_two", tableName2);
            map.put("start_time", START);
            map.put("end_time", END);
            list = syntheSizeQueryService.queryLineByDate11(map);

        } else if ("showMonth".equals(SELECT)) {
            map.put("START", START);
            map.put("END", END);
            String str1[] = START.split("-");
            String name = str1[0];
            String tableName = "tb_kpi_value_year_" + name;
            String str3[] = START.split("-");
            String name2 = str3[0];
            int b = 1;
            int a = Integer.parseInt(name2);
            int c = a + b;
            String tableName2 = "tb_kpi_value_year_" + c;
            String str2[] = END.split("-");
            String name1 = str2[0];
            String tableName1 = "tb_kpi_value_year_" + name1;
            map.put("table_one", tableName);
            map.put("table_three", tableName2);
            map.put("table_two", tableName1);
            map.put("start_time", START);
            map.put("end_time", END);
            list = syntheSizeQueryService.queryMonth1(map);
        } else {
            //2018-08-01         tb_kpi_value_day_20170101
            String str[] = START.split("-");
            String name = str[0] + str[1] + str[2];
            String tableName = "tb_kpi_value_day_" + name;
            map.put("tableName", tableName);
            list = syntheSizeQueryService.queryTime1(map);
        }
//        for (Object o : list) {
//            System.out.println(o);
//        }
        return list;
    }

    //按指标查询文件系统表空间调用方法
    @ResponseBody
    @RequestMapping(value = "/targetFileSystemQuery", method = RequestMethod.POST)
    public List queryFileSystem(String EXT_UNIT_ID, String KPI_ID, String START, String END, String SELECT) {
        HashMap map = new HashMap();
        List list = new ArrayList();
        if (EXT_UNIT_ID != null && KPI_ID != null) {
            map.put("EXT_UNIT_ID", EXT_UNIT_ID);
            map.put("KPI_ID", KPI_ID);
        }
        if ("showDay".equals(SELECT)) {
            map.put("START", START);
            map.put("END", END);
            String str1[] = START.split("-");
            String name = str1[0] + str1[1];
            String tableName = "tb_kpi_value_month_" + name;
            String str2[] = START.split("-");
            String name1 = str2[0] + str2[1];
            int b = 1;
            int a = Integer.parseInt(name1);
            int c = a + b;
            String tableName1 = "tb_kpi_value_month_" + c;
            String str3[] = END.split("-");
            String name2 = str3[0] + str3[1];
            String tableName2 = "tb_kpi_value_month_" + name2;
            map.put("table_one", tableName);
            map.put("table_three", tableName1);
            map.put("table_two", tableName2);
            map.put("start_time", START);
            map.put("end_time", END);
            list = syntheSizeQueryService.queryFileSystemDay(map);

        } else if ("showMonth".equals(SELECT)) {
            map.put("START", START);
            map.put("END", END);
            String str1[] = START.split("-");
            String name = str1[0];
            String tableName = "tb_kpi_value_year_" + name;
            String str3[] = START.split("-");
            String name2 = str3[0];
            int b = 1;
            int a = Integer.parseInt(name2);
            int c = a + b;
            String tableName2 = "tb_kpi_value_year_" + c;
            String str2[] = END.split("-");
            String name1 = str2[0];
            String tableName1 = "tb_kpi_value_year_" + name1;
            map.put("table_one", tableName);
            map.put("table_three", tableName2);
            map.put("table_two", tableName1);
            map.put("start_time", START);
            map.put("end_time", END);
            list = syntheSizeQueryService.queryFileSystemMonth(map);
        } else {
            //2018-08-01         tb_kpi_value_day_20170101
            String str[] = START.split("-");
            String name = str[0] + str[1] + str[2];
            String tableName = "tb_kpi_value_day_" + name;
            map.put("tableName", tableName);
            list = syntheSizeQueryService.queryFileSystem(map);
        }
//        for (Object o : list) {
//            System.out.println(o);
//        }
        return list;
    }
}
